﻿namespace Baddies.Scenes
{
    using System;
    using System.Collections.Generic;
    using System.Diagnostics;
    using System.Linq;
    using System.Text;
    using Baddies.Events;  
    using Baddies.Nodes;
    using Microsoft.Xna.Framework.Content;      

    /// <summary>
    /// A Scene class holds the set of nodes we want to update
    /// as a single group. There should be only one active scene at a time.
    /// A Scene keeps a ContentManager to keep track of all loaded assets.
    /// </summary>
    public class Scene : Node
    {
        /// <summary>
        /// A content manager anyone can access to request loading of
        /// content. 
        /// It gets created when a scene Enters and destroyed 
        /// when it Exits.
        /// </summary>
        private static ContentManager content = null;

        /// <summary>
        /// Gets the content of the scene. 
        /// Must have created a scene first.
        /// </summary>
        /// <value>Reference to the ContentManager of the scene.</value>
        public static ContentManager Content
        {
            get
            {
                if (content == null)
                {
                    // Create content manager.
                    GetGameServicesArg newArg = new GetGameServicesArg();
                    EventManager.GetEV.Trigger("GetGameServices", null, newArg);
                    content = new ContentManager(newArg.Service);
                    content.RootDirectory = "Content";
                }

                return content;
            }
        }

        /// <summary>
        /// Initializes the content manager.
        /// </summary>
        public override void Enter()
        {
            base.Enter();           
        }

        /// <summary>
        /// Disposes of the content manager.
        /// </summary>
        public override void End()
        {
            base.End();
            content.Unload();
            content.Dispose();
            content = null;
        }
    }
}
